package com.sskj.gocoin.v.widget.mychart;

import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import android.text.TextUtils;
import android.view.KeyEvent;
import android.view.View;
import android.view.Window;
import android.widget.TextView;

import com.sskj.gocoin.R;
import com.sskj.gocoin.common.App;



public class ProgressDialogs {
    private Dialog dialog;
    private Context context;

    public ProgressDialogs(Context context) {
        this.context = context;
    }

    public void showDialog() {
        showDialog(App.INSTANCE.getString(R.string.strProgressDialogs200));
    }

    public void showDialog(String msg) {
        dialog = new AlertDialog.Builder(context).create();
        dialog.show();
        dialog.setCancelable(false);
        Window window = dialog.getWindow();
        window.setContentView(R.layout.layout_progress_dialog);
        window.setBackgroundDrawable(new BitmapDrawable(context.getResources(), (Bitmap) null));//去掉黑边
        TextView textView = window.findViewById(R.id.loadingText);
        if (TextUtils.isEmpty(msg)) {
            textView.setVisibility(View.GONE);
        } else {
            textView.setVisibility(View.VISIBLE);
            textView.setText(msg);
        }

        dialog.setOnKeyListener((dialog, keyCode, event) -> {
            if (keyCode == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_DOWN) {
                dialog.dismiss();
            }
            return false;
        });
    }


    public void closeDialog() {
        if (dialog != null) {
            dialog.dismiss();
            dialog = null;
        }
    }


}